﻿using HCQ2_Common;
using HCQ2_Model;
using HCQ2_Model.Log;
using HCQ2_Model.SysModel;
using HCQ2_Model.ViewModel;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web.Mvc;

namespace HCQ2UI_Logic.AdminController
{
    public class SysLogController: BaseLogic
    {
        #region 1.0 首次进入日志页面 +ActionResult List()
        /// <summary>
        ///  首次进入日志页面
        /// </summary>
        /// <returns></returns>
        [HCQ2_Common.Attributes.Load]
        [HttpGet]
        public ActionResult List()
        {
            return View();
        }
        #endregion

        #region 1.1 获取日志列表 +ActionResult GetLogTable(QueryModel param) 
        /// <summary>
        ///  获取日志列表
        /// </summary>
        /// <param name="role"></param>
        /// <returns></returns>
        [HttpPost]
        public ActionResult GetLogTable(QueryModel param)
        {
            int total;
            List<ResultLogModel> list = operateContext.bllSession.T_VROperatorLog.GetLogTableList(param, out total);
            TableModel tModel = new TableModel()
            {
                total = total,
                rows = list
            };
            return Json(tModel, JsonRequestBehavior.AllowGet);
        }
        #endregion

        //**********************************登录日志********************************************
        #region 2. 0 登录日志首次进入+ActionResult LoginPage()
        /// <summary>
        ///  登录日志首次进入
        /// </summary>
        /// <returns></returns>
        [HCQ2_Common.Attributes.Load]
        public ActionResult LoginPage()
        {
            return View();
        }
        #endregion

        #region 2.1 获取登录日志一栏数据 +ActionResult GetLoginListData()
        /// <summary>
        ///  获取登录日志一栏数据
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ActionResult GetLoginListData()
        {
            string keyword = RequestHelper.GetDeStrByName("userName"),//用户名,登录名
                loginSource = RequestHelper.GetStrByName("loginSource"),//登录来源
                orderColumn = RequestHelper.GetStrByName("orderColumn"),//排序字段
                orderType = RequestHelper.GetStrByName("orderType"),//排序类型
                orgUnit = RequestHelper.GetDeStrByName("orgUnit");//单位
            int page = RequestHelper.GetIntByName("page"),
               rows = RequestHelper.GetIntByName("rows"),
               status = RequestHelper.GetIntByName("status"),//状态 -1：全部，0：离线，1：在线
               total=0;
            List<UserLoginLog> list = operateContext.bllSession.T_Login.GetLoginLogData(keyword, orgUnit, page, rows, status,loginSource,orderColumn,orderType, out total);
            TableModel tModel = new TableModel()
            {
                total = total,
                rows = list
            };
            return Json(tModel, JsonRequestBehavior.AllowGet);
        }
        #endregion

        //**********************************3.0 登录详情********************************************
        #region 3. 0 登录日志首次进入+ActionResult LoginPage()
        /// <summary>
        ///  登录日志首次进入
        /// </summary>
        /// <returns></returns>
        [HCQ2_Common.Attributes.Load]
        public ActionResult LoginDetial()
        {
            return View();
        }
        #endregion

        #region 3.1 登录日志详情 +ActionResult GetLoginDetialList(int id)
        /// <summary>
        ///  登录日志详情
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ActionResult GetLoginDetialList(int id)
        {
            int page = RequestHelper.GetIntByName("page"),//第几页
                rows = RequestHelper.GetIntByName("rows");//每页数量
            int total = 0;    
            List<LoginDetialModel> list = operateContext.bllSession.T_Login.GetLoginDetialList(id,page,rows,out total);
            TableModel tModel = new TableModel()
            {
                total = total,
                rows = list
            };
            return Json(tModel, JsonRequestBehavior.AllowGet);
        }
        #endregion
    }
}
